package area;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;


public class CityEvent {
	
	private static final SimpleDateFormat F = new SimpleDateFormat("dd/MM/yyyy HH:mm");
	
	public static final CityEvent MOLE_NIGHT = new CityEvent(Placemark.MOLE_TO,"11/03/2012 19:00","11/03/2012 23:00");
	public static final CityEvent GAME_SILVIO_PIOLA_11_3_2012 = new CityEvent(Placemark.STADIO_SILVIO_PIOLA_NO,"11/03/2012 19:00","11/03/2012 23:00");
	
	public Placemark spot;
	public String startTime;
	public String endTime;
	public Calendar st;
	public Calendar et;
	
	public CityEvent(Placemark spot, String startTime, String endTime) {
		this.spot = spot;
		this.startTime = startTime;
		this.endTime = endTime;
		st = new GregorianCalendar();
		et = new GregorianCalendar();
		try {
			st.setTime(F.parse(startTime));
			et.setTime(F.parse(endTime));
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public CityEvent changeDay(int day,int month,int year) {
		String newStartTime = day+"/"+(month+1)+"/"+year+startTime.substring(startTime.indexOf(" "));
		String newEndTime = day+"/"+(month+1)+"/"+year+endTime.substring(endTime.indexOf(" "));
		return new CityEvent(spot,newStartTime,newEndTime);
	}
	 
	public String toFileName() {
		return toString()+".txt";
	}
	
	public String toString() {
		return spot.name.replaceAll("[/\\:\\s]", "_")+"-"+startTime.replaceAll("[/\\:\\s]", "_")+"-"+endTime.replaceAll("[/\\:\\s]", "_");
	}
	
	
	public double[] dailyPattern(int size) {
		
		if(size != 24 && size !=48) {
			System.err.println("Only size of 24 and 48 are supported. They correspond to hour-based or half-an-hour-based sampling");
			return null;
		}
		
		int startIndex = 0;
		int endIndex = 0;
		
		if(size == 48) {		
			startIndex = 2 * st.get(Calendar.HOUR_OF_DAY) + (st.get(Calendar.MINUTE) < 30 ? 0 : 1);
			endIndex = 2 * et.get(Calendar.HOUR_OF_DAY) + (et.get(Calendar.MINUTE) < 30 ? 0 : 1);
		}
		if(size == 24) {		
			startIndex = st.get(Calendar.HOUR_OF_DAY);
			endIndex = et.get(Calendar.HOUR_OF_DAY);
		}
		double[] dp = new double[size];
		for(int i=startIndex;i<=endIndex;i++)
			dp[i] = 1;
		return dp;
	}
	
	
}
